class VoaInfoManageController < ApplicationController
	##require  "upload_voa_wmv"
	##before_filter :configure_charsets  
	def configure_charsets  
		#puts @headers
		#response.headers["Content-Type"]="text/html;charset=utf-8"  
  end        
	def list
		@voainfos=VoaInfomations.find(:all)
	end
	def new
	end
	def create
		#UploadVoaWmv.testmodule
		#testmodule
		#tempfile=params[:file]
		@filename=save_file
	#	puts  @filename
		puts "begin....."
		puts #{RAILS_ROOT}
		#	puts #{tempfile.original_filename}
		#File.open("#{RAILS_ROOT}/myfile/#{file.original_filename}", "wb+") do |f|
		#	f.write(tempfile.read)
		#end
		#@voainfo=VoaInfomations.create(params[:voainfo])
		
		params[:voainfo][:voiceFilePath]=@filename
		
		VoaInfomations.create(params[:voainfo])
		redirect_to:action=>"list"
	end	
	def save_file 
		unless request.get?   
		
     	
			if filename=upload_file(params[:file]['file'])   
				return filename   
			end   
		end   
  end   
  def upload_file(file)   
		
 		if !file.original_filename.empty?   
			@filename=get_file_name(file.original_filename)    
			File.open("#{RAILS_ROOT}/public/uploads/#{@filename}", "wb") do |f|   
			f.write(file.read)   
			end   
			return @filename  
		end
	end  
  
   def get_file_name(filename)   
     if !filename.nil?   
       Time.now.strftime("%Y%m%d%H%M%S") + '_' + filename   
     end   
   end   
	def show
		@voainfo=VoaInfomations.find(params[:id])
	end
	def edit
		@voainfo=VoaInfomations.find(params[:id])
	end
	def update
		VoaInfomations.update(params[:voainfo][:id],params[:voainfo])
		redirect_to:action => "list"
	end
	def delete
		VoaInfomations.delete(params[:id])
		redirect_to:action=>"list"
	end
end
 